package com.drools.drools.calender;

import com.drools.drools.BaseTest;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.time.Calendar;
import org.quartz.impl.calendar.WeeklyCalendar;


/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2019-05-06
 * Time: 22:13
 * Des:
 */
public class CalenderTest extends BaseTest{
    @Test
    public void test(){
        KieSession kieSession=this.getKieSessionBySessionName("calenderTest-rules");
        kieSession.getCalendars().set("weekday",Weekday);
        kieSession.getCalendars().set("weekdayExclude",weekdayExclude);
        kieSession.fireAllRules();
        kieSession.dispose();
    }

    private static final Calendar Weekday=new Calendar() {
        @Override
        public boolean isTimeIncluded(long timestamp) {
            WeeklyCalendar weeklyCalendar=new WeeklyCalendar();
            weeklyCalendar.setDaysExcluded(new boolean[]{false,false,false,false,false,false,false});
            weeklyCalendar.setDayExcluded(1,true);
            return weeklyCalendar.isTimeIncluded(timestamp);
        }
    };

    private static final Calendar weekdayExclude=new Calendar() {
        @Override
        public boolean isTimeIncluded(long timestamp) {
            WeeklyCalendar weeklyCalendar=new WeeklyCalendar();
            weeklyCalendar.setDaysExcluded(new boolean[]{true,true,true,true,true,true,true});
            weeklyCalendar.setDayExcluded(1,false);
            return weeklyCalendar.isTimeIncluded(timestamp);
        }
    };
}
